<?

require_once ("application.fieldset.inc");

global $_GLOBAL_DBH;
global $_OBJECT_IFACE_PANEL;

$fieldset = new Fieldset (array (
	db_conn=>$_GLOBAL_DBH,
	relation=>"profiles",
	fieldset=>array (
		array (name=>"uid",label=>"ID",type=>"numeric",
				value=>$_REQUEST["user_id"],
				input=>"hidden",primary_key=>true),
		/* array (name=>"company_id",label=>"Company ID",type=>"numeric",
				input=>"field"), */
		array (name=>"phone_1",label=>"Phone 1",type=>"phone",
				input=>"field"),
		array (name=>"ext_1",label=>"Ext 1",type=>"numeric",
				optional=>true,
				input=>"field"),
		array (name=>"phone_2",label=>"Phone 2",type=>"phone",
				input=>"field"),
		array (name=>"ext_2",label=>"Ext 2",type=>"numeric",
				optional=>true,
				input=>"field"),
		array (name=>"fax",label=>"Fax 1",type=>"phone",
				optional=>true,
				input=>"field"),
		array (name=>"address_1",label=>"Address 1",type=>"any",
				input=>"textarea",rows=>3),
		array (name=>"address_2",label=>"Address 2",type=>"any",
				optional=>true,
				input=>"textarea",rows=>3),
		array (name=>"city",label=>"City",type=>"alphanumeric",
				input=>"field"),
		array (name=>"postal",label=>"Postal",type=>"postal",
				input=>"field",optional=>true),
		array (name=>"state",label=>"State",type=>"numeric",
				value=>6,
				input=>"select",
				relation=>array(foreign=>"states",key=>"id",
						field=>"name"),
				options=>"_app_select_query",
				options_params=>"SELECT id,name FROM states",
				columns=>array (key=>"id",value=>"name"),
		),
		array (name=>"country",label=>"Country",type=>"numeric",
				value=>223,
				relation=>array(foreign=>"countries",key=>"id",
						field=>"name"),
				input=>"select",
				options=>"_app_select_query",
				options_params=>"SELECT id,name FROM countries",
				columns=>array (key=>"id",value=>"name"),
		),
		array (name=>"referral",label=>"Referral",type=>"numeric",
				input=>"select",
				options=>array (
					array (id=>"1",name=>"Self"),
					array (id=>"2",name=>"Yahoo"),
					array (id=>"3",name=>"Google"),
					array (id=>"4",name=>"Friend"),
					array (id=>"5",name=>"Customer"),
				),
				columns=>array (key=>"id",value=>"name"),
		),
		array (name=>"calltime",label=>"Calltime",type=>"numeric",
				input=>"select",
				options=>array (
					array (id=>"1",name=>"Morning"),
					array (id=>"2",name=>"Afternoon"),
					array (id=>"3",name=>"Evening"),
					array (id=>"4",name=>"Midnight"),
					array (id=>"5",name=>"Anytime"),
				),
				columns=>array (key=>"id",value=>"name"),
		),
		array (name=>"notes",label=>"Notes",type=>"character",
				optional=>true,
				input=>"textarea"),
	)
));

$fieldset->parse ();

$return = "/fs_users.php?fs_action=view&fs_tab=main&user_id={$_REQUEST["user_id"]}";

$fs_options = array (
	modify=>array (label=>"Modify"),
	update=>array (label=>"Update"),
	cancel=>array (label=>"Cancel"),
	close=>array (label=>"Close",
			redirect=>dirname ($_SERVER["PHP_SELF"]) . $return),
);

$image_options = array (size=>$_REQUEST["_img_size"]);

list ($fs_input, $fs_action, $store, $valid, $success) =

	_app_process_fieldset (array (
		fieldset=>$fieldset,
		fs_options=>$fs_options,
		fs_action=>($_REQUEST["fs_action"] ?
				$_REQUEST["fs_action"] :
				"addnew"),
));

if ($store && $success && isset ($_REQUEST["image"])) {

	if (!file_exists (_GLOBAL_ROOT_PATH . "/img/profile"))

		mkdir (_GLOBAL_ROOT_PATH . "/img/profile");

	_app_store_file ("image",$_SERVER["DOCUMENT_ROOT"] . _GLOBAL_URI_PATH .
			"/img/profile/",
			"{$fieldset->get_field ("id")->get_variable ("value")}.jpg");

}

$_OBJECT_FIELDSET_CONTROL =_app_create_fieldset_object (array (
	fieldset_id=>"fs_user_profiles",
	db_conn=>$_GLOBAL_DBH,
	fieldset=>$fieldset,
	fs_enctype=>"multipart/form-data",
	fs_action=>$fs_action,
	fs_input=>$fs_input,
	fs_link=>"fs_users.php?fs_action=view&fs_tab=profiles&user_id={$_REQUEST["user_id"]}",
	fs_options=>$fs_options,
));

$_OBJECT_IFACE_TABBING_PANEL->insert_container ($_OBJECT_FIELDSET_CONTROL);

?>
